<?php

namespace Xin\Plugin\Facades;

use think\facade\Route;
use Xin\Plugin\ThinkPHP\PluginDispatch;
use Xin\Plugin\ThinkPHP\Url;

if (class_exists(\Illuminate\Support\Facades\Facade::class)) {
    class Facade extends \Illuminate\Support\Facades\Facade
    {

    }
} elseif (class_exists(\think\Facade::class)) {
    class Facade extends \think\Facade
    {

    }
}

/**
 * @method bool has($plugin) static
 * @method \Xin\Contracts\Plugin\PluginInfo plugin($plugin) static
 * @method string pluginClass($plugin) static
 * @method string controllerClass($plugin, $controller, $layer = 'controller') static
 * @method mixed invoke(\think\Request $request, $plugin, $controller, $action) static
 * @method \Xin\Support\Collection plugins() static
 * @method void boot() static
 * @method string rootPath($path = '') static
 * @method string path($path = '') static
 */
class Plugin extends Facade
{

    /**
     * 获取当前Facade对应类名（或者已经绑定的容器对象标识）
     *
     * @access protected
     * @return string
     */
    protected static function getFacadeClass()
    {
        return 'pluginManager';
    }

    /**
     * 获取组件的注册名称。
     *
     * @return string
     */
    protected static function getFacadeAccessor()
    {
        return 'pluginManager';
    }

    /**
     * 路由到自定义调度对象
     *
     * @param callable $pluginBootCallback
     */
    public static function routes($prefix = 'app', $pluginBootCallback = null)
    {
        Route::any($prefix . '/:plugin/:controller/[:action]', PluginDispatch::class);
        Url::$pluginPrefix = $prefix;
        PluginDispatch::$pluginBootCallback = $pluginBootCallback;
    }

    /**
     * 获取路由前缀
     *
     * @return string
     */
    public static function getPrefix()
    {
        return Url::$pluginPrefix;
    }

}
